<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django.utils.feedgenerator &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../../index.html" />
    <link rel="up" title="django" href="../../django.html" />



 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-utils-feedgenerator">
            
  <h1>Source code for django.utils.feedgenerator</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Syndication feed generation library -- used for generating RSS, etc.</span>

<span class="sd">Sample usage:</span>

<span class="sd">&gt;&gt;&gt; from django.utils import feedgenerator</span>
<span class="sd">&gt;&gt;&gt; feed = feedgenerator.Rss201rev2Feed(</span>
<span class="sd">...     title=&quot;Poynter E-Media Tidbits&quot;,</span>
<span class="sd">...     link=&quot;http://www.poynter.org/column.asp?id=31&quot;,</span>
<span class="sd">...     description=&quot;A group Weblog by the sharpest minds in online media/journalism/publishing.&quot;,</span>
<span class="sd">...     language=&quot;en&quot;,</span>
<span class="sd">... )</span>
<span class="sd">&gt;&gt;&gt; feed.add_item(</span>
<span class="sd">...     title=&quot;Hello&quot;,</span>
<span class="sd">...     link=&quot;http://www.holovaty.com/test/&quot;,</span>
<span class="sd">...     description=&quot;Testing.&quot;</span>
<span class="sd">... )</span>
<span class="sd">&gt;&gt;&gt; with open(&#39;test.rss&#39;, &#39;w&#39;) as fp:</span>
<span class="sd">...     feed.write(fp, &#39;utf-8&#39;)</span>

<span class="sd">For definitions of the different versions of RSS, see:</span>
<span class="sd">http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/02/04/incompatible-rss</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">unicode_literals</span>

<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">from</span> <span class="nn">django.utils.xmlutils</span> <span class="kn">import</span> <span class="n">SimplerXMLGenerator</span>
<span class="kn">from</span> <span class="nn">django.utils.encoding</span> <span class="kn">import</span> <span class="n">force_text</span><span class="p">,</span> <span class="n">iri_to_uri</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">datetime_safe</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">six</span>
<span class="kn">from</span> <span class="nn">django.utils.six</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">from</span> <span class="nn">django.utils.six.moves.urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span>
<span class="kn">from</span> <span class="nn">django.utils.timezone</span> <span class="kn">import</span> <span class="n">is_aware</span>


<span class="k">def</span> <span class="nf">rfc2822_date</span><span class="p">(</span><span class="n">date</span><span class="p">):</span>
    <span class="c"># We can&#39;t use strftime() because it produces locale-dependent results, so</span>
    <span class="c"># we have to map english month and day names manually</span>
    <span class="n">months</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;Jan&#39;</span><span class="p">,</span> <span class="s">&#39;Feb&#39;</span><span class="p">,</span> <span class="s">&#39;Mar&#39;</span><span class="p">,</span> <span class="s">&#39;Apr&#39;</span><span class="p">,</span> <span class="s">&#39;May&#39;</span><span class="p">,</span> <span class="s">&#39;Jun&#39;</span><span class="p">,</span> <span class="s">&#39;Jul&#39;</span><span class="p">,</span> <span class="s">&#39;Aug&#39;</span><span class="p">,</span> <span class="s">&#39;Sep&#39;</span><span class="p">,</span> <span class="s">&#39;Oct&#39;</span><span class="p">,</span> <span class="s">&#39;Nov&#39;</span><span class="p">,</span> <span class="s">&#39;Dec&#39;</span><span class="p">,)</span>
    <span class="n">days</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;Mon&#39;</span><span class="p">,</span> <span class="s">&#39;Tue&#39;</span><span class="p">,</span> <span class="s">&#39;Wed&#39;</span><span class="p">,</span> <span class="s">&#39;Thu&#39;</span><span class="p">,</span> <span class="s">&#39;Fri&#39;</span><span class="p">,</span> <span class="s">&#39;Sat&#39;</span><span class="p">,</span> <span class="s">&#39;Sun&#39;</span><span class="p">)</span>
    <span class="c"># Support datetime objects older than 1900</span>
    <span class="n">date</span> <span class="o">=</span> <span class="n">datetime_safe</span><span class="o">.</span><span class="n">new_datetime</span><span class="p">(</span><span class="n">date</span><span class="p">)</span>
    <span class="c"># We do this ourselves to be timezone aware, email.Utils is not tz aware.</span>
    <span class="n">dow</span> <span class="o">=</span> <span class="n">days</span><span class="p">[</span><span class="n">date</span><span class="o">.</span><span class="n">weekday</span><span class="p">()]</span>
    <span class="n">month</span> <span class="o">=</span> <span class="n">months</span><span class="p">[</span><span class="n">date</span><span class="o">.</span><span class="n">month</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
    <span class="n">time_str</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">, </span><span class="si">%%</span><span class="s">d </span><span class="si">%s</span><span class="s"> </span><span class="si">%%</span><span class="s">Y </span><span class="si">%%</span><span class="s">H:</span><span class="si">%%</span><span class="s">M:</span><span class="si">%%</span><span class="s">S &#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">dow</span><span class="p">,</span> <span class="n">month</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">six</span><span class="o">.</span><span class="n">PY2</span><span class="p">:</span>             <span class="c"># strftime returns a byte string in Python 2</span>
        <span class="n">time_str</span> <span class="o">=</span> <span class="n">time_str</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s">&#39;utf-8&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_aware</span><span class="p">(</span><span class="n">date</span><span class="p">):</span>
        <span class="n">offset</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">tzinfo</span><span class="o">.</span><span class="n">utcoffset</span><span class="p">(</span><span class="n">date</span><span class="p">)</span>
        <span class="n">timezone</span> <span class="o">=</span> <span class="p">(</span><span class="n">offset</span><span class="o">.</span><span class="n">days</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">60</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">offset</span><span class="o">.</span><span class="n">seconds</span> <span class="o">//</span> <span class="mi">60</span><span class="p">)</span>
        <span class="n">hour</span><span class="p">,</span> <span class="n">minute</span> <span class="o">=</span> <span class="nb">divmod</span><span class="p">(</span><span class="n">timezone</span><span class="p">,</span> <span class="mi">60</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">time_str</span> <span class="o">+</span> <span class="s">&#39;</span><span class="si">%+03d%02d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">hour</span><span class="p">,</span> <span class="n">minute</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">time_str</span> <span class="o">+</span> <span class="s">&#39;-0000&#39;</span>


<span class="k">def</span> <span class="nf">rfc3339_date</span><span class="p">(</span><span class="n">date</span><span class="p">):</span>
    <span class="c"># Support datetime objects older than 1900</span>
    <span class="n">date</span> <span class="o">=</span> <span class="n">datetime_safe</span><span class="o">.</span><span class="n">new_datetime</span><span class="p">(</span><span class="n">date</span><span class="p">)</span>
    <span class="n">time_str</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;%Y-%m-</span><span class="si">%d</span><span class="s">T%H:%M:%S&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">six</span><span class="o">.</span><span class="n">PY2</span><span class="p">:</span>             <span class="c"># strftime returns a byte string in Python 2</span>
        <span class="n">time_str</span> <span class="o">=</span> <span class="n">time_str</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s">&#39;utf-8&#39;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">is_aware</span><span class="p">(</span><span class="n">date</span><span class="p">):</span>
        <span class="n">offset</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">tzinfo</span><span class="o">.</span><span class="n">utcoffset</span><span class="p">(</span><span class="n">date</span><span class="p">)</span>
        <span class="n">timezone</span> <span class="o">=</span> <span class="p">(</span><span class="n">offset</span><span class="o">.</span><span class="n">days</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">60</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">offset</span><span class="o">.</span><span class="n">seconds</span> <span class="o">//</span> <span class="mi">60</span><span class="p">)</span>
        <span class="n">hour</span><span class="p">,</span> <span class="n">minute</span> <span class="o">=</span> <span class="nb">divmod</span><span class="p">(</span><span class="n">timezone</span><span class="p">,</span> <span class="mi">60</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">time_str</span> <span class="o">+</span> <span class="s">&#39;</span><span class="si">%+03d</span><span class="s">:</span><span class="si">%02d</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">hour</span><span class="p">,</span> <span class="n">minute</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">time_str</span> <span class="o">+</span> <span class="s">&#39;Z&#39;</span>


<div class="viewcode-block" id="get_tag_uri"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.get_tag_uri">[docs]</a><span class="k">def</span> <span class="nf">get_tag_uri</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">date</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Creates a TagURI.</span>

<span class="sd">    See http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">bits</span> <span class="o">=</span> <span class="n">urlparse</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
    <span class="n">d</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
    <span class="k">if</span> <span class="n">date</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">d</span> <span class="o">=</span> <span class="s">&#39;,</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">datetime_safe</span><span class="o">.</span><span class="n">new_datetime</span><span class="p">(</span><span class="n">date</span><span class="p">)</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s">&#39;%Y-%m-</span><span class="si">%d</span><span class="s">&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="s">&#39;tag:</span><span class="si">%s%s</span><span class="s">:</span><span class="si">%s</span><span class="s">/</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">bits</span><span class="o">.</span><span class="n">hostname</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="n">bits</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="n">bits</span><span class="o">.</span><span class="n">fragment</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="SyndicationFeed"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed">[docs]</a><span class="k">class</span> <span class="nc">SyndicationFeed</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="s">&quot;Base class for all syndication feeds. Subclasses should provide write()&quot;</span>
<div class="viewcode-block" id="SyndicationFeed.__init__"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.__init__">[docs]</a>    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">link</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">language</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">author_email</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">author_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">author_link</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">subtitle</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">categories</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">feed_url</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">feed_copyright</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">feed_guid</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="n">to_unicode</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">force_text</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">strings_only</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">categories</span><span class="p">:</span>
            <span class="n">categories</span> <span class="o">=</span> <span class="p">[</span><span class="n">force_text</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">categories</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">ttl</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># Force ints to unicode</span>
            <span class="n">ttl</span> <span class="o">=</span> <span class="n">force_text</span><span class="p">(</span><span class="n">ttl</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feed</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">title</span><span class="p">),</span>
            <span class="s">&#39;link&#39;</span><span class="p">:</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">link</span><span class="p">),</span>
            <span class="s">&#39;description&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">description</span><span class="p">),</span>
            <span class="s">&#39;language&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">language</span><span class="p">),</span>
            <span class="s">&#39;author_email&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">author_email</span><span class="p">),</span>
            <span class="s">&#39;author_name&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">author_name</span><span class="p">),</span>
            <span class="s">&#39;author_link&#39;</span><span class="p">:</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">author_link</span><span class="p">),</span>
            <span class="s">&#39;subtitle&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">subtitle</span><span class="p">),</span>
            <span class="s">&#39;categories&#39;</span><span class="p">:</span> <span class="n">categories</span> <span class="ow">or</span> <span class="p">(),</span>
            <span class="s">&#39;feed_url&#39;</span><span class="p">:</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">feed_url</span><span class="p">),</span>
            <span class="s">&#39;feed_copyright&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">feed_copyright</span><span class="p">),</span>
            <span class="s">&#39;id&#39;</span><span class="p">:</span> <span class="n">feed_guid</span> <span class="ow">or</span> <span class="n">link</span><span class="p">,</span>
            <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="n">ttl</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">items</span> <span class="o">=</span> <span class="p">[]</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.add_item"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.add_item">[docs]</a>    <span class="k">def</span> <span class="nf">add_item</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="p">,</span> <span class="n">link</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">author_email</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">author_name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">author_link</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">pubdate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">comments</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">unique_id</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">unique_id_is_permalink</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">enclosure</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">categories</span><span class="o">=</span><span class="p">(),</span> <span class="n">item_copyright</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ttl</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">updateddate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds an item to the feed. All args are expected to be Python Unicode</span>
<span class="sd">        objects except pubdate and updateddate, which are datetime.datetime</span>
<span class="sd">        objects, and enclosure, which is an instance of the Enclosure class.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">to_unicode</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">s</span><span class="p">:</span> <span class="n">force_text</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">strings_only</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">categories</span><span class="p">:</span>
            <span class="n">categories</span> <span class="o">=</span> <span class="p">[</span><span class="n">to_unicode</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">categories</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">ttl</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># Force ints to unicode</span>
            <span class="n">ttl</span> <span class="o">=</span> <span class="n">force_text</span><span class="p">(</span><span class="n">ttl</span><span class="p">)</span>
        <span class="n">item</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;title&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">title</span><span class="p">),</span>
            <span class="s">&#39;link&#39;</span><span class="p">:</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">link</span><span class="p">),</span>
            <span class="s">&#39;description&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">description</span><span class="p">),</span>
            <span class="s">&#39;author_email&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">author_email</span><span class="p">),</span>
            <span class="s">&#39;author_name&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">author_name</span><span class="p">),</span>
            <span class="s">&#39;author_link&#39;</span><span class="p">:</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">author_link</span><span class="p">),</span>
            <span class="s">&#39;pubdate&#39;</span><span class="p">:</span> <span class="n">pubdate</span><span class="p">,</span>
            <span class="s">&#39;updateddate&#39;</span><span class="p">:</span> <span class="n">updateddate</span><span class="p">,</span>
            <span class="s">&#39;comments&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">comments</span><span class="p">),</span>
            <span class="s">&#39;unique_id&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">unique_id</span><span class="p">),</span>
            <span class="s">&#39;unique_id_is_permalink&#39;</span><span class="p">:</span> <span class="n">unique_id_is_permalink</span><span class="p">,</span>
            <span class="s">&#39;enclosure&#39;</span><span class="p">:</span> <span class="n">enclosure</span><span class="p">,</span>
            <span class="s">&#39;categories&#39;</span><span class="p">:</span> <span class="n">categories</span> <span class="ow">or</span> <span class="p">(),</span>
            <span class="s">&#39;item_copyright&#39;</span><span class="p">:</span> <span class="n">to_unicode</span><span class="p">(</span><span class="n">item_copyright</span><span class="p">),</span>
            <span class="s">&#39;ttl&#39;</span><span class="p">:</span> <span class="n">ttl</span><span class="p">,</span>
        <span class="p">}</span>
        <span class="n">item</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.num_items"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.num_items">[docs]</a>    <span class="k">def</span> <span class="nf">num_items</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.root_attributes"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.root_attributes">[docs]</a>    <span class="k">def</span> <span class="nf">root_attributes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return extra attributes to place on the root (i.e. feed/channel) element.</span>
<span class="sd">        Called from write().</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{}</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.add_root_elements"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.add_root_elements">[docs]</a>    <span class="k">def</span> <span class="nf">add_root_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add elements in the root (i.e. feed/channel) element. Called</span>
<span class="sd">        from write().</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">pass</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.item_attributes"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.item_attributes">[docs]</a>    <span class="k">def</span> <span class="nf">item_attributes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return extra attributes to place on each item (i.e. item/entry) element.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="p">{}</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.add_item_elements"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.add_item_elements">[docs]</a>    <span class="k">def</span> <span class="nf">add_item_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add elements on each item (i.e. item/entry) element.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">pass</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.write"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.write">[docs]</a>    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">encoding</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Outputs the feed in the given encoding to outfile, which is a file-like</span>
<span class="sd">        object. Subclasses should override this.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s">&#39;subclasses of SyndicationFeed must provide a write() method&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.writeString"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.writeString">[docs]</a>    <span class="k">def</span> <span class="nf">writeString</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">encoding</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the feed in the given encoding as a string.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">encoding</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">s</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="SyndicationFeed.latest_post_date"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.SyndicationFeed.latest_post_date">[docs]</a>    <span class="k">def</span> <span class="nf">latest_post_date</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the latest item&#39;s pubdate or updateddate. If no items</span>
<span class="sd">        have either of these attributes this returns the current date/time.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">latest_date</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="n">date_keys</span> <span class="o">=</span> <span class="p">(</span><span class="s">&#39;updateddate&#39;</span><span class="p">,</span> <span class="s">&#39;pubdate&#39;</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">date_key</span> <span class="ow">in</span> <span class="n">date_keys</span><span class="p">:</span>
                <span class="n">item_date</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">date_key</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">item_date</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">latest_date</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">item_date</span> <span class="o">&gt;</span> <span class="n">latest_date</span><span class="p">:</span>
                        <span class="n">latest_date</span> <span class="o">=</span> <span class="n">item_date</span>

        <span class="k">return</span> <span class="n">latest_date</span> <span class="ow">or</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>

</div></div>
<div class="viewcode-block" id="Enclosure"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.Enclosure">[docs]</a><span class="k">class</span> <span class="nc">Enclosure</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="s">&quot;Represents an RSS enclosure&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">length</span><span class="p">,</span> <span class="n">mime_type</span><span class="p">):</span>
        <span class="s">&quot;All args are expected to be Python Unicode objects&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mime_type</span> <span class="o">=</span> <span class="n">length</span><span class="p">,</span> <span class="n">mime_type</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">url</span> <span class="o">=</span> <span class="n">iri_to_uri</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="RssFeed"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.RssFeed">[docs]</a><span class="k">class</span> <span class="nc">RssFeed</span><span class="p">(</span><span class="n">SyndicationFeed</span><span class="p">):</span>
    <span class="n">mime_type</span> <span class="o">=</span> <span class="s">&#39;application/rss+xml; charset=utf-8&#39;</span>

    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">encoding</span><span class="p">):</span>
        <span class="n">handler</span> <span class="o">=</span> <span class="n">SimplerXMLGenerator</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">encoding</span><span class="p">)</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">startDocument</span><span class="p">()</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&quot;rss&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rss_attributes</span><span class="p">())</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&quot;channel&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_attributes</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_root_elements</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_items</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">endChannelElement</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;rss&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">rss_attributes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;version&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_version</span><span class="p">,</span>
                <span class="s">&quot;xmlns:atom&quot;</span><span class="p">:</span> <span class="s">&quot;http://www.w3.org/2005/Atom&quot;</span><span class="p">}</span>

    <span class="k">def</span> <span class="nf">write_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&#39;item&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_attributes</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_item_elements</span><span class="p">(</span><span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">)</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;item&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">add_root_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;description&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_url&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;atom:link&quot;</span><span class="p">,</span> <span class="bp">None</span><span class="p">,</span>
                    <span class="p">{</span><span class="s">&quot;rel&quot;</span><span class="p">:</span> <span class="s">&quot;self&quot;</span><span class="p">,</span> <span class="s">&quot;href&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_url&#39;</span><span class="p">]})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;language&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;language&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;language&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">cat</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;categories&#39;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;category&quot;</span><span class="p">,</span> <span class="n">cat</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_copyright&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;copyright&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_copyright&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;lastBuildDate&quot;</span><span class="p">,</span> <span class="n">rfc2822_date</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">latest_post_date</span><span class="p">()))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;ttl&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">endChannelElement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;channel&quot;</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="RssUserland091Feed"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.RssUserland091Feed">[docs]</a><span class="k">class</span> <span class="nc">RssUserland091Feed</span><span class="p">(</span><span class="n">RssFeed</span><span class="p">):</span>
    <span class="n">_version</span> <span class="o">=</span> <span class="s">&quot;0.91&quot;</span>

    <span class="k">def</span> <span class="nf">add_item_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;description&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">])</span>

</div>
<div class="viewcode-block" id="Rss201rev2Feed"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.Rss201rev2Feed">[docs]</a><span class="k">class</span> <span class="nc">Rss201rev2Feed</span><span class="p">(</span><span class="n">RssFeed</span><span class="p">):</span>
    <span class="c"># Spec: http://blogs.law.harvard.edu/tech/rss</span>
    <span class="n">_version</span> <span class="o">=</span> <span class="s">&quot;2.0&quot;</span>

    <span class="k">def</span> <span class="nf">add_item_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;description&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">])</span>

        <span class="c"># Author information.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_name&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_email&quot;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">,</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;author_email&#39;</span><span class="p">],</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_name&#39;</span><span class="p">]))</span>
        <span class="k">elif</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_email&quot;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_email&quot;</span><span class="p">])</span>
        <span class="k">elif</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_name&quot;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;dc:creator&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&quot;author_name&quot;</span><span class="p">],</span> <span class="p">{</span><span class="s">&quot;xmlns:dc&quot;</span><span class="p">:</span> <span class="s">&quot;http://purl.org/dc/elements/1.1/&quot;</span><span class="p">})</span>

        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;pubdate&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;pubDate&quot;</span><span class="p">,</span> <span class="n">rfc2822_date</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;pubdate&#39;</span><span class="p">]))</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;comments&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;comments&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;comments&#39;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;unique_id&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">guid_attrs</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;unique_id_is_permalink&#39;</span><span class="p">),</span> <span class="nb">bool</span><span class="p">):</span>
                <span class="n">guid_attrs</span><span class="p">[</span><span class="s">&#39;isPermaLink&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span>
                    <span class="n">item</span><span class="p">[</span><span class="s">&#39;unique_id_is_permalink&#39;</span><span class="p">])</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;guid&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;unique_id&#39;</span><span class="p">],</span> <span class="n">guid_attrs</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;ttl&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;ttl&#39;</span><span class="p">])</span>

        <span class="c"># Enclosure.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;enclosure&quot;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">,</span>
                <span class="p">{</span><span class="s">&quot;url&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">url</span><span class="p">,</span> <span class="s">&quot;length&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">length</span><span class="p">,</span>
                    <span class="s">&quot;type&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">mime_type</span><span class="p">})</span>

        <span class="c"># Categories.</span>
        <span class="k">for</span> <span class="n">cat</span> <span class="ow">in</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;categories&#39;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;category&quot;</span><span class="p">,</span> <span class="n">cat</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Atom1Feed"><a class="viewcode-back" href="../../../ref/utils.html#django.utils.feedgenerator.Atom1Feed">[docs]</a><span class="k">class</span> <span class="nc">Atom1Feed</span><span class="p">(</span><span class="n">SyndicationFeed</span><span class="p">):</span>
    <span class="c"># Spec: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html</span>
    <span class="n">mime_type</span> <span class="o">=</span> <span class="s">&#39;application/atom+xml; charset=utf-8&#39;</span>
    <span class="n">ns</span> <span class="o">=</span> <span class="s">&quot;http://www.w3.org/2005/Atom&quot;</span>

    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">encoding</span><span class="p">):</span>
        <span class="n">handler</span> <span class="o">=</span> <span class="n">SimplerXMLGenerator</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">encoding</span><span class="p">)</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">startDocument</span><span class="p">()</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&#39;feed&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_attributes</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add_root_elements</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">write_items</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;feed&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">root_attributes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;language&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&quot;xmlns&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ns</span><span class="p">,</span> <span class="s">&quot;xml:lang&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;language&#39;</span><span class="p">]}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s">&quot;xmlns&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">ns</span><span class="p">}</span>

    <span class="k">def</span> <span class="nf">add_root_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;rel&quot;</span><span class="p">:</span> <span class="s">&quot;alternate&quot;</span><span class="p">,</span> <span class="s">&quot;href&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">]})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_url&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;rel&quot;</span><span class="p">:</span> <span class="s">&quot;self&quot;</span><span class="p">,</span> <span class="s">&quot;href&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_url&#39;</span><span class="p">]})</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;id&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;id&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;updated&quot;</span><span class="p">,</span> <span class="n">rfc3339_date</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">latest_post_date</span><span class="p">()))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_name&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">,</span> <span class="p">{})</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_name&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_email&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;email&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_email&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_link&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;uri&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;author_link&#39;</span><span class="p">])</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;subtitle&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;subtitle&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;subtitle&#39;</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">cat</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;categories&#39;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;category&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;term&quot;</span><span class="p">:</span> <span class="n">cat</span><span class="p">})</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_copyright&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;rights&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed</span><span class="p">[</span><span class="s">&#39;feed_copyright&#39;</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">write_items</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">items</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&quot;entry&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">item_attributes</span><span class="p">(</span><span class="n">item</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">add_item_elements</span><span class="p">(</span><span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">)</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;entry&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">add_item_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">handler</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;title&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;title&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;href&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">],</span> <span class="s">&quot;rel&quot;</span><span class="p">:</span> <span class="s">&quot;alternate&quot;</span><span class="p">})</span>

        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;pubdate&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&#39;published&#39;</span><span class="p">,</span> <span class="n">rfc3339_date</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;pubdate&#39;</span><span class="p">]))</span>

        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;updateddate&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&#39;updated&#39;</span><span class="p">,</span> <span class="n">rfc3339_date</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;updateddate&#39;</span><span class="p">]))</span>

        <span class="c"># Author information.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_name&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">startElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">,</span> <span class="p">{})</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_name&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_email&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;email&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_email&#39;</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_link&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;uri&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;author_link&#39;</span><span class="p">])</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">endElement</span><span class="p">(</span><span class="s">&quot;author&quot;</span><span class="p">)</span>

        <span class="c"># Unique ID.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;unique_id&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">unique_id</span> <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;unique_id&#39;</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">unique_id</span> <span class="o">=</span> <span class="n">get_tag_uri</span><span class="p">(</span><span class="n">item</span><span class="p">[</span><span class="s">&#39;link&#39;</span><span class="p">],</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;pubdate&#39;</span><span class="p">])</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;id&quot;</span><span class="p">,</span> <span class="n">unique_id</span><span class="p">)</span>

        <span class="c"># Summary.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;summary&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;description&#39;</span><span class="p">],</span> <span class="p">{</span><span class="s">&quot;type&quot;</span><span class="p">:</span> <span class="s">&quot;html&quot;</span><span class="p">})</span>

        <span class="c"># Enclosure.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;link&quot;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">,</span>
                <span class="p">{</span><span class="s">&quot;rel&quot;</span><span class="p">:</span> <span class="s">&quot;enclosure&quot;</span><span class="p">,</span>
                 <span class="s">&quot;href&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">url</span><span class="p">,</span>
                 <span class="s">&quot;length&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">length</span><span class="p">,</span>
                 <span class="s">&quot;type&quot;</span><span class="p">:</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;enclosure&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">mime_type</span><span class="p">})</span>

        <span class="c"># Categories.</span>
        <span class="k">for</span> <span class="n">cat</span> <span class="ow">in</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;categories&#39;</span><span class="p">]:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;category&quot;</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;term&quot;</span><span class="p">:</span> <span class="n">cat</span><span class="p">})</span>

        <span class="c"># Rights.</span>
        <span class="k">if</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;item_copyright&#39;</span><span class="p">]</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">addQuickElement</span><span class="p">(</span><span class="s">&quot;rights&quot;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="s">&#39;item_copyright&#39;</span><span class="p">])</span>

<span class="c"># This isolates the decision of what the system default is, so calling code can</span>
<span class="c"># do &quot;feedgenerator.DefaultFeed&quot; instead of &quot;feedgenerator.Rss201rev2Feed&quot;.</span></div>
<span class="n">DefaultFeed</span> <span class="o">=</span> <span class="n">Rss201rev2Feed</span>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3>Browse</h3>
  <ul>
    
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../../index.html">Module code</a>
        
          <ul><li><a href="../../django.html">django</a>
        
        <ul><li>django.utils.feedgenerator</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>